﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Business;

namespace University.Workshop.Presenters.Cistern.Register
{
    public class PresenterRegisterFirstStep
    {
        
        IFirstStepForRegiserCistern view;
        public PresenterRegisterFirstStep(IFirstStepForRegiserCistern view)
        {
            this.view = view;
        }

        public void UpdateData()
        {
            view.PersonId = view.CisternToRegister.Person.PersonId;
            view.PersonNames = view.CisternToRegister.Person.Names;
            view.PersonLastNames = view.CisternToRegister.Person.LastNames;
            view.PersonNewPhones = view.CisternToRegister.Person.Phone;
            ChargePhonesToList();
        }

        public void ChargePhonesToList()
        {
            view.PersonPhones = view.PersonNewPhones.Split(',').ToList().Where(x=>x!=string.Empty).ToList();
        }

        public void ChargeDataPerson()
        {
            view.CisternToRegister.Person.PersonId = view.PersonId;
            view.CisternToRegister.Person.Names = view.PersonNames;
            view.CisternToRegister.Person.LastNames = view.PersonLastNames;
            view.CisternToRegister.Person.Phone = view.PersonNewPhones;
        }

        public void VerifyIfDriverIdExist()
        {
            Model.Person person= ManagerPerson.GetPersonByPersonId(new Model.Person() { PersonId = view.PersonId });
                if (person != null)
                {
                    view.SystemMessage = "El ci de la persona que ingreso ya existe los datos seran actualizados.";
                    view.PersonLastNames = person.LastNames;
                    view.PersonNames = person.Names;
                    view.PersonNewPhones = person.Phone;
                    ChargePhonesToList();
                
                }
        }
    }
}
